Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
0.00% |
0 / 264 |
|
0.00% |
0 / 121 |
|
0.00% |
0 / 154 |
|
0.00% |
0 / 32 |
CRAP | |
0.00% |
0 / 1 |
| Repository | |
0.00% |
0 / 264 |
|
0.00% |
0 / 121 |
|
0.00% |
0 / 154 |
|
0.00% |
0 / 32 |
5402 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| newDataObject | |
0.00% |
0 / 4 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| get | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| exists | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCollector | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getSchemaMap | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| validate | |
0.00% |
0 / 19 |
|
0.00% |
0 / 5 |
|
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| add | |
0.00% |
0 / 6 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| edit | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| delete | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| deleteByContextId | |
0.00% |
0 / 5 |
|
0.00% |
0 / 4 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getArrayIdByRoleId | |
0.00% |
0 / 5 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| getByRoleIds | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| userUserGroups | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| getUserUserGroupsContextIds | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| userInGroup | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| userOnMasthead | |
0.00% |
0 / 10 |
|
0.00% |
0 / 6 |
|
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
20 | |||
| getUserUserGroupMastheadStatus | |
0.00% |
0 / 10 |
|
0.00% |
0 / 8 |
|
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
20 | |||
| contextHasGroup | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| assignUserToGroup | |
0.00% |
0 / 20 |
|
0.00% |
0 / 16 |
|
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
72 | |||
| deleteAssignmentsByUserId | |
0.00% |
0 / 13 |
|
0.00% |
0 / 9 |
|
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
30 | |||
| endAssignments | |
0.00% |
0 / 10 |
|
0.00% |
0 / 5 |
|
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| getUserGroupsByStage | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| removeGroupFromStage | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAssignedStagesByUserGroupId | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUserCountByContextId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFirstSubmitAsAuthorUserGroup | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| installSettings | |
0.00% |
0 / 44 |
|
0.00% |
0 / 22 |
|
0.00% |
0 / 69 |
|
0.00% |
0 / 1 |
110 | |||
| installLocale | |
0.00% |
0 / 10 |
|
0.00% |
0 / 6 |
|
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| getMastheadUserIdsByRoleIds | |
0.00% |
0 / 35 |
|
0.00% |
0 / 6 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
20 | |||
| forgetEditorialMastheadCache | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| forgetEditorialHistoryCache | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @file classes/userGroup/Repository.php |
| 4 | * |
| 5 | * Copyright (c) 2014-2020 Simon Fraser University |
| 6 | * Copyright (c) 2000-2020 John Willinsky |
| 7 | * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. |
| 8 | * |
| 9 | * @class \PKP\userGroup\Repository |
| 10 | * |
| 11 | * @brief A repository to find and manage userGroups. |
| 12 | */ |
| 13 | |
| 14 | namespace PKP\userGroup; |
| 15 | |
| 16 | use APP\core\Application; |
| 17 | use APP\core\Request; |
| 18 | use APP\facades\Repo; |
| 19 | use Carbon\Carbon; |
| 20 | use DateInterval; |
| 21 | use Illuminate\Support\Collection; |
| 22 | use Illuminate\Support\Facades\Cache; |
| 23 | use Illuminate\Support\LazyCollection; |
| 24 | use PKP\core\Core; |
| 25 | use PKP\db\DAORegistry; |
| 26 | use PKP\facades\Locale; |
| 27 | use PKP\plugins\Hook; |
| 28 | use PKP\security\Role; |
| 29 | use PKP\services\PKPSchemaService; |
| 30 | use PKP\site\SiteDAO; |
| 31 | use PKP\userGroup\relationships\enums\UserUserGroupMastheadStatus; |
| 32 | use PKP\userGroup\relationships\enums\UserUserGroupStatus; |
| 33 | use PKP\userGroup\relationships\UserGroupStage; |
| 34 | use PKP\userGroup\relationships\UserUserGroup; |
| 35 | use PKP\validation\ValidatorFactory; |
| 36 | use PKP\xml\PKPXMLParser; |
| 37 | use stdClass; |
| 38 | |
| 39 | class Repository |
| 40 | { |
| 41 | /** |
| 42 | * A list of roles not able to change submissionMetadataEdit permission option. |
| 43 | */ |
| 44 | public const NOT_CHANGE_METADATA_EDIT_PERMISSION_ROLES = [Role::ROLE_ID_MANAGER]; |
| 45 | |
| 46 | /** @var string Max lifetime for the Editorial Masthead and Editorial History users cache. */ |
| 47 | public const MAX_EDITORIAL_MASTHEAD_CACHE_LIFETIME = '1 year'; |
| 48 | |
| 49 | /** @var DAO */ |
| 50 | public $dao; |
| 51 | |
| 52 | /** @var string $schemaMap The name of the class to map this entity to its schema */ |
| 53 | public $schemaMap = maps\Schema::class; |
| 54 | |
| 55 | /** @var Request */ |
| 56 | protected $request; |
| 57 | |
| 58 | /** @var PKPSchemaService<UserGroup> */ |
| 59 | protected $schemaService; |
| 60 | |
| 61 | public function __construct(DAO $dao, Request $request, PKPSchemaService $schemaService) |
| 62 | { |
| 63 | $this->dao = $dao; |
| 64 | $this->request = $request; |
| 65 | $this->schemaService = $schemaService; |
| 66 | } |
| 67 | |
| 68 | /** @copydoc DAO::newDataObject() */ |
| 69 | public function newDataObject(array $params = []): UserGroup |
| 70 | { |
| 71 | $object = $this->dao->newDataObject(); |
| 72 | if (!empty($params)) { |
| 73 | $object->setAllData($params); |
| 74 | } |
| 75 | return $object; |
| 76 | } |
| 77 | |
| 78 | /** @copydoc DAO::get() */ |
| 79 | public function get(int $id, ?int $contextId = null): ?UserGroup |
| 80 | { |
| 81 | return $this->dao->get($id, $contextId); |
| 82 | } |
| 83 | |
| 84 | /** @copydoc DAO::exists() */ |
| 85 | public function exists(int $id, ?int $contextId = null): bool |
| 86 | { |
| 87 | return $this->dao->exists($id, $contextId); |
| 88 | } |
| 89 | |
| 90 | /** @copydoc DAO::getCollector() */ |
| 91 | public function getCollector(): Collector |
| 92 | { |
| 93 | return app(Collector::class); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Get an instance of the map class for mapping |
| 98 | * user groups to their schema |
| 99 | */ |
| 100 | public function getSchemaMap(): maps\Schema |
| 101 | { |
| 102 | return app('maps')->withExtensions($this->schemaMap); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Validate properties for a user group |
| 107 | * |
| 108 | * Perform validation checks on data used to add or edit a user group. |
| 109 | * |
| 110 | * @param UserGroup|null $userGroup The userGroup being edited. Pass `null` if creating a new userGroup |
| 111 | * @param array $props A key/value array with the new data to validate |
| 112 | * @param array $allowedLocales The context's supported submission locales |
| 113 | * @param string $primaryLocale The submission's primary locale |
| 114 | * |
| 115 | * @return array A key/value array with validation errors. Empty if no errors |
| 116 | * |
| 117 | * @hook UserGroup::validate [[$errors, $userGroup, $props, $allowedLocales, $primaryLocale]] |
| 118 | */ |
| 119 | public function validate($userGroup, $props, $allowedLocales, $primaryLocale) |
| 120 | { |
| 121 | $schemaService = app()->get('schema'); |
| 122 | |
| 123 | $validator = ValidatorFactory::make( |
| 124 | $props, |
| 125 | $schemaService->getValidationRules(PKPSchemaService::SCHEMA_USER_GROUP, $allowedLocales) |
| 126 | ); |
| 127 | |
| 128 | // Check required fields |
| 129 | ValidatorFactory::required( |
| 130 | $validator, |
| 131 | $userGroup, |
| 132 | $schemaService->getRequiredProps(PKPSchemaService::SCHEMA_USER_GROUP), |
| 133 | $schemaService->getMultilingualProps(PKPSchemaService::SCHEMA_USER_GROUP), |
| 134 | $allowedLocales, |
| 135 | $primaryLocale |
| 136 | ); |
| 137 | |
| 138 | // Check for input from disallowed locales |
| 139 | ValidatorFactory::allowedLocales($validator, $schemaService->getMultilingualProps(PKPSchemaService::SCHEMA_USER_GROUP), $allowedLocales); |
| 140 | |
| 141 | $errors = []; |
| 142 | if ($validator->fails()) { |
| 143 | $errors = $schemaService->formatValidationErrors($validator->errors()); |
| 144 | } |
| 145 | |
| 146 | Hook::call('UserGroup::validate', [$errors, $userGroup, $props, $allowedLocales, $primaryLocale]); |
| 147 | |
| 148 | return $errors; |
| 149 | } |
| 150 | |
| 151 | public function add(UserGroup $userGroup): int |
| 152 | { |
| 153 | $userGroupId = $this->dao->insert($userGroup); |
| 154 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 155 | |
| 156 | Hook::call('UserGroup::add', [$userGroup]); |
| 157 | |
| 158 | // Clear editorial masthead cache if the new role should be added to the masthead |
| 159 | // Because it is a new role, no need to clear editorial history chache |
| 160 | if ($userGroup->getMasthead()) { |
| 161 | self::forgetEditorialMastheadCache($userGroup->getContextId()); |
| 162 | } |
| 163 | return $userGroup->getId(); |
| 164 | } |
| 165 | |
| 166 | public function edit(UserGroup $userGroup, array $params) |
| 167 | { |
| 168 | $newUserGroup = Repo::userGroup()->newDataObject(array_merge($userGroup->_data, $params)); |
| 169 | |
| 170 | Hook::call('UserGroup::edit', [$newUserGroup, $userGroup, $params]); |
| 171 | |
| 172 | $this->dao->update($newUserGroup); |
| 173 | |
| 174 | // Clear editorial masthead and history cache if the role is on the masthead |
| 175 | if ($userGroup->getMasthead()) { |
| 176 | self::forgetEditorialMastheadCache($userGroup->getContextId()); |
| 177 | self::forgetEditorialHistoryCache($userGroup->getContextId()); |
| 178 | } |
| 179 | |
| 180 | Repo::userGroup()->get($newUserGroup->getId()); |
| 181 | } |
| 182 | |
| 183 | public function delete(UserGroup $userGroup) |
| 184 | { |
| 185 | Hook::call('UserGroup::delete::before', [$userGroup]); |
| 186 | |
| 187 | $this->dao->delete($userGroup); |
| 188 | |
| 189 | Hook::call('UserGroup::delete', [$userGroup]); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Delete all user groups assigned to a certain context by contextId |
| 194 | */ |
| 195 | public function deleteByContextId(int $contextId) |
| 196 | { |
| 197 | $userGroupIds = Repo::userGroup()->getCollector() |
| 198 | ->filterByContextIds([$contextId]) |
| 199 | ->getIds(); |
| 200 | |
| 201 | foreach ($userGroupIds as $userGroupId) { |
| 202 | $this->dao->deleteById($userGroupId); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * Return all user group ids given a certain role id |
| 208 | * |
| 209 | * @param int $roleId |
| 210 | */ |
| 211 | public function getArrayIdByRoleId($roleId, ?int $contextId = null): array |
| 212 | { |
| 213 | $collector = Repo::userGroup()->getCollector() |
| 214 | ->filterByRoleIds([$roleId]); |
| 215 | |
| 216 | if ($contextId) { |
| 217 | $collector->filterByContextIds([$contextId]); |
| 218 | } |
| 219 | |
| 220 | return $collector->getIds()->toArray(); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Return all user group ids given a certain role id |
| 225 | * |
| 226 | * @param ?bool $default Give null for all user groups, else define whether it is default |
| 227 | * |
| 228 | * @return LazyCollection<int,UserGroup> |
| 229 | */ |
| 230 | public function getByRoleIds(array $roleIds, int $contextId, ?bool $default = null): LazyCollection |
| 231 | { |
| 232 | $collector = Repo::userGroup() |
| 233 | ->getCollector() |
| 234 | ->filterByRoleIds($roleIds) |
| 235 | ->filterByContextIds([$contextId]) |
| 236 | ->filterByIsDefault($default); |
| 237 | |
| 238 | return $collector->getMany(); |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Return all, active or ended user groups ids for a user id |
| 243 | * |
| 244 | * @return LazyCollection<int,UserGroup> |
| 245 | */ |
| 246 | public function userUserGroups(int $userId, ?int $contextId = null, ?UserUserGroupStatus $userUserGroupStatus = UserUserGroupStatus::STATUS_ACTIVE): LazyCollection |
| 247 | { |
| 248 | $collector = Repo::userGroup() |
| 249 | ->getCollector() |
| 250 | ->filterByUserIds([$userId]) |
| 251 | ->filterByUserUserGroupStatus($userUserGroupStatus); |
| 252 | |
| 253 | if ($contextId) { |
| 254 | $collector->filterByContextIds([$contextId]); |
| 255 | } |
| 256 | |
| 257 | return $collector->getMany(); |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Return all context IDs for masthead user groups the given user is or was assigned to |
| 262 | * |
| 263 | * @return Collection of context IDs |
| 264 | */ |
| 265 | public function getUserUserGroupsContextIds(int $userId): Collection |
| 266 | { |
| 267 | return Repo::userGroup() |
| 268 | ->getCollector() |
| 269 | ->filterByUserIds([$userId]) |
| 270 | ->filterByUserUserGroupStatus(UserUserGroupStatus::STATUS_ALL) |
| 271 | ->filterByMasthead(true) |
| 272 | ->getQueryBuilder() |
| 273 | ->pluck('context_id') |
| 274 | ->unique(); |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * return whether a user is in a user group |
| 279 | */ |
| 280 | public function userInGroup(int $userId, int $userGroupId): bool |
| 281 | { |
| 282 | return UserUserGroup::withUserId($userId) |
| 283 | ->withUserGroupId($userGroupId) |
| 284 | ->withActive() |
| 285 | ->get() |
| 286 | ->isNotEmpty(); |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * return whether an active user in a user group should be displayed on the masthead |
| 291 | */ |
| 292 | public function userOnMasthead(int $userId, ?int $userGroupId): bool |
| 293 | { |
| 294 | if ($userGroupId) { |
| 295 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 296 | if (!$userGroup->getMasthead()) { |
| 297 | return false; |
| 298 | } |
| 299 | } |
| 300 | $query = UserUserGroup::withUserId($userId) |
| 301 | ->withActive() |
| 302 | ->withMasthead(); |
| 303 | if ($userGroupId) { |
| 304 | $query->withUserGroupId($userGroupId); |
| 305 | } |
| 306 | return $query->get()->isNotEmpty(); |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Get user masthead status for a user group the user is currently active in |
| 311 | */ |
| 312 | public function getUserUserGroupMastheadStatus(int $userId, int $userGroupId): UserUserGroupMastheadStatus |
| 313 | { |
| 314 | $masthead = UserUserGroup::withUserId($userId) |
| 315 | ->withUserGroupId($userGroupId) |
| 316 | ->withActive() |
| 317 | ->pluck('masthead'); |
| 318 | switch ($masthead[0]) { |
| 319 | case 1: |
| 320 | return UserUserGroupMastheadStatus::STATUS_ON; |
| 321 | case 0: |
| 322 | return UserUserGroupMastheadStatus::STATUS_OFF; |
| 323 | case null: |
| 324 | return UserUserGroupMastheadStatus::STATUS_NULL; |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * return whether a context has a specific user group |
| 330 | */ |
| 331 | public function contextHasGroup(int $contextId, int $userGroupId): bool |
| 332 | { |
| 333 | return Repo::userGroup() |
| 334 | ->getCollector() |
| 335 | ->filterByContextIds([$contextId]) |
| 336 | ->filterByUserGroupIds([$userGroupId]) |
| 337 | ->getCount() > 0; |
| 338 | } |
| 339 | |
| 340 | /** |
| 341 | * Assign a user to a role |
| 342 | * |
| 343 | * @param string|null $startDate The date in ISO (YYYY-MM-DD HH:MM:SS) format |
| 344 | * @param string|null $endDate The date in ISO (YYYY-MM-DD HH:MM:SS) format |
| 345 | */ |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 349 | return null; |
| 350 | } |
| 351 | |
| 352 | $dateStart = $startDate ?? Core::getCurrentDate(); |
| 353 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 354 | // user_user_group's masthead does not inherit from the user_group's masthead, |
| 355 | // it needs to be specified (when accepting an invitations). |
| 356 | switch ($mastheadStatus) { |
| 357 | case UserUserGroupMastheadStatus::STATUS_ON: |
| 358 | $masthead = 1; |
| 359 | break; |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 361 | $masthead = 0; |
| 362 | break; |
| 363 | default: |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 365 | } |
| 366 | // Clear editorial masthead cache if a new user is assigned to a masthead role |
| 367 | if ($userGroup->getMasthead()) { |
| 368 | self::forgetEditorialMastheadCache($userGroup->getContextId()); |
| 369 | } |
| 370 | return UserUserGroup::create([ |
| 371 | 'userId' => $userId, |
| 372 | 'userGroupId' => $userGroupId, |
| 373 | 'dateStart' => $dateStart, |
| 374 | 'dateEnd' => $endDate, |
| 375 | 'masthead' => $masthead, |
| 376 | ]); |
| 377 | } |
| 378 | |
| 379 | /** |
| 380 | * Remove all user role assignments. This should be used only when merging i.e. fully deleting an user. |
| 381 | */ |
| 382 | public function deleteAssignmentsByUserId(int $userId, ?int $userGroupId = null): bool |
| 383 | { |
| 384 | if (!$userGroupId) { |
| 385 | $contextIds = $this->getUserUserGroupsContextIds($userId); |
| 386 | foreach ($contextIds as $contextId) { |
| 387 | self::forgetEditorialMastheadCache($contextId); |
| 388 | self::forgetEditorialHistoryCache($contextId); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 393 | |
| 394 | if ($userGroupId) { |
| 395 | $query->withUserGroupId($userGroupId); |
| 396 | $userGroup = $this->get($userGroupId); |
| 397 | if ($userGroup->getMasthead()) { |
| 398 | self::forgetEditorialMastheadCache($contextId); |
| 399 | self::forgetEditorialHistoryCache($contextId); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | return $query->delete(); |
| 404 | } |
| 405 | |
| 406 | public function endAssignments(int $contextId, int $userId, ?int $userGroupId = null): void |
| 407 | { |
| 408 | // Clear editorial masthead and history cache if the user was displayed on the masthead for the given role |
| 409 | if ($this->userOnMasthead($userId, $userGroupId)) { |
| 410 | self::forgetEditorialMastheadCache($contextId); |
| 411 | self::forgetEditorialHistoryCache($contextId); |
| 412 | } |
| 413 | |
| 414 | $dateEnd = Core::getCurrentDate(); |
| 415 | $query = UserUserGroup::withContextId($contextId) |
| 416 | ->withUserId($userId) |
| 417 | ->withActive(); |
| 418 | if ($userGroupId) { |
| 419 | $query->withUserGroupId($userGroupId); |
| 420 | } |
| 421 | $query->update(['date_end' => $dateEnd]); |
| 422 | } |
| 423 | |
| 424 | /** |
| 425 | * Get the user groups assigned to each stage. |
| 426 | * |
| 427 | * @param null|mixed $roleId |
| 428 | * @param null|mixed $count |
| 429 | * |
| 430 | * @return LazyCollection<int,UserGroup> |
| 431 | */ |
| 432 | public function getUserGroupsByStage(int $contextId, $stageId, $roleId = null, $count = null): LazyCollection |
| 433 | { |
| 434 | $userGroups = $this->getCollector() |
| 435 | ->filterByContextIds([$contextId]) |
| 436 | ->filterByStageIds([$stageId]); |
| 437 | |
| 438 | if ($roleId) { |
| 439 | $userGroups->filterByRoleIds([$roleId]); |
| 440 | } |
| 441 | |
| 442 | $userGroups->orderBy(Collector::ORDERBY_ROLE_ID); |
| 443 | |
| 444 | return $userGroups->getMany(); |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * Remove a user group from a stage |
| 449 | */ |
| 450 | public function removeGroupFromStage(int $contextId, int $userGroupId, int $stageId): bool |
| 451 | { |
| 452 | return UserGroupStage::withContextId($contextId) |
| 453 | ->withUserGroupId($userGroupId) |
| 454 | ->withStageId($stageId) |
| 455 | ->delete(); |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * Get all stages assigned to one user group in one context. |
| 460 | * |
| 461 | * @param int $contextId The context ID. |
| 462 | * @param int $userGroupId The user group ID |
| 463 | * |
| 464 | */ |
| 465 | public function getAssignedStagesByUserGroupId(int $contextId, int $userGroupId): Collection |
| 466 | { |
| 467 | return UserGroupStage::withContextId($contextId) |
| 468 | ->withUserGroupId($userGroupId) |
| 469 | ->pluck('stage_id'); |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * Retrieves a keyed Collection (key = user_group_id, value = count) with the amount of active users for each user group |
| 474 | */ |
| 475 | public function getUserCountByContextId(?int $contextId = null): Collection |
| 476 | { |
| 477 | return $this->dao->getUserCountByContextId($contextId); |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * Get the user group a new author may be assigned to |
| 482 | * when they make their first submission, if they are |
| 483 | * not already assigned to an author user group. |
| 484 | * |
| 485 | * This returns the first user group with ROLE_ID_AUTHOR |
| 486 | * that permits self-registration. |
| 487 | */ |
| 488 | public function getFirstSubmitAsAuthorUserGroup(int $contextId): ?UserGroup |
| 489 | { |
| 490 | return Repo::userGroup() |
| 491 | ->getCollector() |
| 492 | ->filterByContextIds([$contextId]) |
| 493 | ->filterByRoleIds([Role::ROLE_ID_AUTHOR]) |
| 494 | ->filterByPermitSelfRegistration(true) |
| 495 | ->limit(1) |
| 496 | ->getMany() |
| 497 | ->first(); |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * Load the XML file and move the settings to the DB |
| 502 | * |
| 503 | * @param int $contextId |
| 504 | * @param string $filename |
| 505 | * |
| 506 | * @return bool true === success |
| 507 | */ |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 518 | return false; |
| 519 | } |
| 520 | |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 581 | |
| 582 | /** |
| 583 | * use the locale keys stored in the settings table to install the locale settings |
| 584 | * |
| 585 | * @param string $locale |
| 586 | * @param ?int $contextId |
| 587 | */ |
| 588 | public function installLocale($locale, ?int $contextId = null) |
| 589 | { |
| 590 | $userGroupsCollector = $this->getCollector(); |
| 591 | |
| 592 | if (isset($contextId)) { |
| 593 | $userGroupsCollector->filterByContextIds([$contextId]); |
| 594 | } |
| 595 | |
| 596 | $userGroups = $userGroupsCollector->getMany(); |
| 597 | |
| 598 | foreach ($userGroups as $userGroup) { |
| 599 | $nameKey = $userGroup->getData('nameLocaleKey'); |
| 600 | $userGroup->setData('name', __($nameKey, [], $locale), $locale); |
| 601 | $abbrevKey = $userGroup->getData('abbrevLocaleKey'); |
| 602 | $userGroup->setData('abbrev', __($abbrevKey, [], $locale), $locale); |
| 603 | |
| 604 | $this->edit($userGroup, []); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * Cache/get cached array of masthead user IDs grouped by masthead role IDs [user_group_id => [user_ids]] |
| 610 | * |
| 611 | * @param array $mastheadRoles Masthead roles, filtered by the given context ID, and sorted as they should appear on the Editorial Masthead and Editorial History page |
| 612 | * |
| 613 | */ |
| 614 | public function getMastheadUserIdsByRoleIds(array $mastheadRoles, int $contextId, UserUserGroupStatus $userUserGroupStatus = UserUserGroupStatus::STATUS_ACTIVE): array |
| 615 | { |
| 616 | $key = __METHOD__; |
| 617 | switch ($userUserGroupStatus) { |
| 618 | case UserUserGroupStatus::STATUS_ACTIVE: |
| 619 | $key .= 'EditorialMasthead'; |
| 620 | break; |
| 621 | case UserUserGroupStatus::STATUS_ENDED: |
| 622 | $key .= 'EditorialHistory'; |
| 623 | break; |
| 624 | } |
| 625 | $key .= $contextId . self::MAX_EDITORIAL_MASTHEAD_CACHE_LIFETIME; |
| 626 | $expiration = DateInterval::createFromDateString(static::MAX_EDITORIAL_MASTHEAD_CACHE_LIFETIME); |
| 627 | $allUsersIdsGroupedByUserGroupId = Cache::remember($key, $expiration, function () use ($mastheadRoles, $contextId, $userUserGroupStatus) { |
| 628 | $mastheadRolesIds = array_map( |
| 629 | function (UserGroup $item) use ($contextId) { |
| 630 | if ($item->getContextId() == $contextId) { |
| 631 | return $item->getId(); |
| 632 | } |
| 633 | }, |
| 634 | $mastheadRoles |
| 635 | ); |
| 636 | // Query that gets all users that are or were active in the given masthead roles |
| 637 | // and that have accepted to be displayed on the masthead for the roles. |
| 638 | // Sort the results by role ID and user family name. |
| 639 | $usersCollector = Repo::user()->getCollector(); |
| 640 | $usersQuery = $usersCollector |
| 641 | ->filterByContextIds([$contextId]) |
| 642 | ->filterByUserGroupIds($mastheadRolesIds) |
| 643 | ->filterByUserUserGroupStatus($userUserGroupStatus) |
| 644 | ->filterByUserUserGroupMastheadStatus(UserUserGroupMastheadStatus::STATUS_ON) |
| 645 | ->orderBy($usersCollector::ORDERBY_FAMILYNAME, $usersCollector::ORDER_DIR_ASC, [Locale::getLocale(), Application::get()->getRequest()->getSite()->getPrimaryLocale()]) |
| 646 | ->orderByUserGroupIds($mastheadRolesIds) |
| 647 | ->getQueryBuilder() |
| 648 | ->get(); |
| 649 | |
| 650 | // Get unique user IDs grouped by user group ID |
| 651 | $userIdsByUserGroupId = $usersQuery->mapToGroups(function (stdClass $item, int $key) { |
| 652 | return [$item->user_group_id => $item->user_id]; |
| 653 | })->map(function ($item) { |
| 654 | return collect($item)->unique(); |
| 655 | }); |
| 656 | return $userIdsByUserGroupId->toArray(); |
| 657 | }); |
| 658 | return $allUsersIdsGroupedByUserGroupId; |
| 659 | } |
| 660 | |
| 661 | /** |
| 662 | * Clear editorial masthead cache |
| 663 | */ |
| 664 | public static function forgetEditorialMastheadCache(int $contextId) |
| 665 | { |
| 666 | Cache::forget('PKP\userGroup\Repository::getMastheadUserIdsByRoleIdsEditorialMasthead' . $contextId . self::MAX_EDITORIAL_MASTHEAD_CACHE_LIFETIME); |
| 667 | } |
| 668 | |
| 669 | /** |
| 670 | * Clear editorial history cache |
| 671 | */ |
| 672 | public static function forgetEditorialHistoryCache(int $contextId) |
| 673 | { |
| 674 | Cache::forget('PKP\userGroup\Repository::getMastheadUserIdsByRoleIdsEditorialHistory' . $contextId . self::MAX_EDITORIAL_MASTHEAD_CACHE_LIFETIME); |
| 675 | } |
| 676 | |
| 677 | } |
Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not
necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once.
Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 627 | $allUsersIdsGroupedByUserGroupId = Cache::remember($key, $expiration, function () use ($mastheadRoles, $contextId, $userUserGroupStatus) { |
| 628 | $mastheadRolesIds = array_map( |
| 629 | function (UserGroup $item) use ($contextId) { |
| 630 | if ($item->getContextId() == $contextId) { |
| 631 | return $item->getId(); |
| 632 | } |
| 633 | }, |
| 634 | $mastheadRoles |
| 635 | ); |
| 636 | // Query that gets all users that are or were active in the given masthead roles |
| 637 | // and that have accepted to be displayed on the masthead for the roles. |
| 638 | // Sort the results by role ID and user family name. |
| 639 | $usersCollector = Repo::user()->getCollector(); |
| 640 | $usersQuery = $usersCollector |
| 641 | ->filterByContextIds([$contextId]) |
| 642 | ->filterByUserGroupIds($mastheadRolesIds) |
| 643 | ->filterByUserUserGroupStatus($userUserGroupStatus) |
| 644 | ->filterByUserUserGroupMastheadStatus(UserUserGroupMastheadStatus::STATUS_ON) |
| 645 | ->orderBy($usersCollector::ORDERBY_FAMILYNAME, $usersCollector::ORDER_DIR_ASC, [Locale::getLocale(), Application::get()->getRequest()->getSite()->getPrimaryLocale()]) |
| 646 | ->orderByUserGroupIds($mastheadRolesIds) |
| 647 | ->getQueryBuilder() |
| 648 | ->get(); |
| 649 | |
| 650 | // Get unique user IDs grouped by user group ID |
| 651 | $userIdsByUserGroupId = $usersQuery->mapToGroups(function (stdClass $item, int $key) { |
| 652 | return [$item->user_group_id => $item->user_id]; |
| 653 | })->map(function ($item) { |
| 654 | return collect($item)->unique(); |
| 655 | }); |
| 656 | return $userIdsByUserGroupId->toArray(); |
| 657 | }); |
| 61 | public function __construct(DAO $dao, Request $request, PKPSchemaService $schemaService) |
| 62 | { |
| 63 | $this->dao = $dao; |
| 64 | $this->request = $request; |
| 65 | $this->schemaService = $schemaService; |
| 66 | } |
| 151 | public function add(UserGroup $userGroup): int |
| 152 | { |
| 153 | $userGroupId = $this->dao->insert($userGroup); |
| 154 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 155 | |
| 156 | Hook::call('UserGroup::add', [$userGroup]); |
| 157 | |
| 158 | // Clear editorial masthead cache if the new role should be added to the masthead |
| 159 | // Because it is a new role, no need to clear editorial history chache |
| 160 | if ($userGroup->getMasthead()) { |
| 161 | self::forgetEditorialMastheadCache($userGroup->getContextId()); |
| 162 | } |
| 163 | return $userGroup->getId(); |
| 163 | return $userGroup->getId(); |
| 164 | } |
| 151 | public function add(UserGroup $userGroup): int |
| 152 | { |
| 153 | $userGroupId = $this->dao->insert($userGroup); |
| 154 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 155 | |
| 156 | Hook::call('UserGroup::add', [$userGroup]); |
| 157 | |
| 158 | // Clear editorial masthead cache if the new role should be added to the masthead |
| 159 | // Because it is a new role, no need to clear editorial history chache |
| 160 | if ($userGroup->getMasthead()) { |
| 163 | return $userGroup->getId(); |
| 164 | } |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 349 | return null; |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 352 | $dateStart = $startDate ?? Core::getCurrentDate(); |
| 353 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 354 | // user_user_group's masthead does not inherit from the user_group's masthead, |
| 355 | // it needs to be specified (when accepting an invitations). |
| 356 | switch ($mastheadStatus) { |
| 357 | case UserUserGroupMastheadStatus::STATUS_ON: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 365 | } |
| 366 | // Clear editorial masthead cache if a new user is assigned to a masthead role |
| 367 | if ($userGroup->getMasthead()) { |
| 367 | if ($userGroup->getMasthead()) { |
| 368 | self::forgetEditorialMastheadCache($userGroup->getContextId()); |
| 369 | } |
| 370 | return UserUserGroup::create([ |
| 370 | return UserUserGroup::create([ |
| 371 | 'userId' => $userId, |
| 372 | 'userGroupId' => $userGroupId, |
| 373 | 'dateStart' => $dateStart, |
| 374 | 'dateEnd' => $endDate, |
| 375 | 'masthead' => $masthead, |
| 376 | ]); |
| 377 | } |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 352 | $dateStart = $startDate ?? Core::getCurrentDate(); |
| 353 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 354 | // user_user_group's masthead does not inherit from the user_group's masthead, |
| 355 | // it needs to be specified (when accepting an invitations). |
| 356 | switch ($mastheadStatus) { |
| 357 | case UserUserGroupMastheadStatus::STATUS_ON: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 365 | } |
| 366 | // Clear editorial masthead cache if a new user is assigned to a masthead role |
| 367 | if ($userGroup->getMasthead()) { |
| 367 | if ($userGroup->getMasthead()) { |
| 370 | return UserUserGroup::create([ |
| 371 | 'userId' => $userId, |
| 372 | 'userGroupId' => $userGroupId, |
| 373 | 'dateStart' => $dateStart, |
| 374 | 'dateEnd' => $endDate, |
| 375 | 'masthead' => $masthead, |
| 376 | ]); |
| 377 | } |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 352 | $dateStart = $startDate ?? Core::getCurrentDate(); |
| 353 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 354 | // user_user_group's masthead does not inherit from the user_group's masthead, |
| 355 | // it needs to be specified (when accepting an invitations). |
| 356 | switch ($mastheadStatus) { |
| 357 | case UserUserGroupMastheadStatus::STATUS_ON: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 365 | } |
| 366 | // Clear editorial masthead cache if a new user is assigned to a masthead role |
| 367 | if ($userGroup->getMasthead()) { |
| 367 | if ($userGroup->getMasthead()) { |
| 368 | self::forgetEditorialMastheadCache($userGroup->getContextId()); |
| 369 | } |
| 370 | return UserUserGroup::create([ |
| 370 | return UserUserGroup::create([ |
| 371 | 'userId' => $userId, |
| 372 | 'userGroupId' => $userGroupId, |
| 373 | 'dateStart' => $dateStart, |
| 374 | 'dateEnd' => $endDate, |
| 375 | 'masthead' => $masthead, |
| 376 | ]); |
| 377 | } |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 352 | $dateStart = $startDate ?? Core::getCurrentDate(); |
| 353 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 354 | // user_user_group's masthead does not inherit from the user_group's masthead, |
| 355 | // it needs to be specified (when accepting an invitations). |
| 356 | switch ($mastheadStatus) { |
| 357 | case UserUserGroupMastheadStatus::STATUS_ON: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 365 | } |
| 366 | // Clear editorial masthead cache if a new user is assigned to a masthead role |
| 367 | if ($userGroup->getMasthead()) { |
| 367 | if ($userGroup->getMasthead()) { |
| 370 | return UserUserGroup::create([ |
| 371 | 'userId' => $userId, |
| 372 | 'userGroupId' => $userGroupId, |
| 373 | 'dateStart' => $dateStart, |
| 374 | 'dateEnd' => $endDate, |
| 375 | 'masthead' => $masthead, |
| 376 | ]); |
| 377 | } |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 352 | $dateStart = $startDate ?? Core::getCurrentDate(); |
| 353 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 354 | // user_user_group's masthead does not inherit from the user_group's masthead, |
| 355 | // it needs to be specified (when accepting an invitations). |
| 356 | switch ($mastheadStatus) { |
| 357 | case UserUserGroupMastheadStatus::STATUS_ON: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 361 | $masthead = 0; |
| 362 | break; |
| 367 | if ($userGroup->getMasthead()) { |
| 368 | self::forgetEditorialMastheadCache($userGroup->getContextId()); |
| 369 | } |
| 370 | return UserUserGroup::create([ |
| 370 | return UserUserGroup::create([ |
| 371 | 'userId' => $userId, |
| 372 | 'userGroupId' => $userGroupId, |
| 373 | 'dateStart' => $dateStart, |
| 374 | 'dateEnd' => $endDate, |
| 375 | 'masthead' => $masthead, |
| 376 | ]); |
| 377 | } |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 352 | $dateStart = $startDate ?? Core::getCurrentDate(); |
| 353 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 354 | // user_user_group's masthead does not inherit from the user_group's masthead, |
| 355 | // it needs to be specified (when accepting an invitations). |
| 356 | switch ($mastheadStatus) { |
| 357 | case UserUserGroupMastheadStatus::STATUS_ON: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 361 | $masthead = 0; |
| 362 | break; |
| 367 | if ($userGroup->getMasthead()) { |
| 370 | return UserUserGroup::create([ |
| 371 | 'userId' => $userId, |
| 372 | 'userGroupId' => $userGroupId, |
| 373 | 'dateStart' => $dateStart, |
| 374 | 'dateEnd' => $endDate, |
| 375 | 'masthead' => $masthead, |
| 376 | ]); |
| 377 | } |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 352 | $dateStart = $startDate ?? Core::getCurrentDate(); |
| 353 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 354 | // user_user_group's masthead does not inherit from the user_group's masthead, |
| 355 | // it needs to be specified (when accepting an invitations). |
| 356 | switch ($mastheadStatus) { |
| 357 | case UserUserGroupMastheadStatus::STATUS_ON: |
| 358 | $masthead = 1; |
| 359 | break; |
| 367 | if ($userGroup->getMasthead()) { |
| 368 | self::forgetEditorialMastheadCache($userGroup->getContextId()); |
| 369 | } |
| 370 | return UserUserGroup::create([ |
| 370 | return UserUserGroup::create([ |
| 371 | 'userId' => $userId, |
| 372 | 'userGroupId' => $userGroupId, |
| 373 | 'dateStart' => $dateStart, |
| 374 | 'dateEnd' => $endDate, |
| 375 | 'masthead' => $masthead, |
| 376 | ]); |
| 377 | } |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 352 | $dateStart = $startDate ?? Core::getCurrentDate(); |
| 353 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 354 | // user_user_group's masthead does not inherit from the user_group's masthead, |
| 355 | // it needs to be specified (when accepting an invitations). |
| 356 | switch ($mastheadStatus) { |
| 357 | case UserUserGroupMastheadStatus::STATUS_ON: |
| 358 | $masthead = 1; |
| 359 | break; |
| 367 | if ($userGroup->getMasthead()) { |
| 370 | return UserUserGroup::create([ |
| 371 | 'userId' => $userId, |
| 372 | 'userGroupId' => $userGroupId, |
| 373 | 'dateStart' => $dateStart, |
| 374 | 'dateEnd' => $endDate, |
| 375 | 'masthead' => $masthead, |
| 376 | ]); |
| 377 | } |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 349 | return null; |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 352 | $dateStart = $startDate ?? Core::getCurrentDate(); |
| 353 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 354 | // user_user_group's masthead does not inherit from the user_group's masthead, |
| 355 | // it needs to be specified (when accepting an invitations). |
| 356 | switch ($mastheadStatus) { |
| 357 | case UserUserGroupMastheadStatus::STATUS_ON: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 365 | } |
| 366 | // Clear editorial masthead cache if a new user is assigned to a masthead role |
| 367 | if ($userGroup->getMasthead()) { |
| 367 | if ($userGroup->getMasthead()) { |
| 368 | self::forgetEditorialMastheadCache($userGroup->getContextId()); |
| 369 | } |
| 370 | return UserUserGroup::create([ |
| 370 | return UserUserGroup::create([ |
| 371 | 'userId' => $userId, |
| 372 | 'userGroupId' => $userGroupId, |
| 373 | 'dateStart' => $dateStart, |
| 374 | 'dateEnd' => $endDate, |
| 375 | 'masthead' => $masthead, |
| 376 | ]); |
| 377 | } |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 352 | $dateStart = $startDate ?? Core::getCurrentDate(); |
| 353 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 354 | // user_user_group's masthead does not inherit from the user_group's masthead, |
| 355 | // it needs to be specified (when accepting an invitations). |
| 356 | switch ($mastheadStatus) { |
| 357 | case UserUserGroupMastheadStatus::STATUS_ON: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 365 | } |
| 366 | // Clear editorial masthead cache if a new user is assigned to a masthead role |
| 367 | if ($userGroup->getMasthead()) { |
| 367 | if ($userGroup->getMasthead()) { |
| 370 | return UserUserGroup::create([ |
| 371 | 'userId' => $userId, |
| 372 | 'userGroupId' => $userGroupId, |
| 373 | 'dateStart' => $dateStart, |
| 374 | 'dateEnd' => $endDate, |
| 375 | 'masthead' => $masthead, |
| 376 | ]); |
| 377 | } |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 352 | $dateStart = $startDate ?? Core::getCurrentDate(); |
| 353 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 354 | // user_user_group's masthead does not inherit from the user_group's masthead, |
| 355 | // it needs to be specified (when accepting an invitations). |
| 356 | switch ($mastheadStatus) { |
| 357 | case UserUserGroupMastheadStatus::STATUS_ON: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 365 | } |
| 366 | // Clear editorial masthead cache if a new user is assigned to a masthead role |
| 367 | if ($userGroup->getMasthead()) { |
| 367 | if ($userGroup->getMasthead()) { |
| 368 | self::forgetEditorialMastheadCache($userGroup->getContextId()); |
| 369 | } |
| 370 | return UserUserGroup::create([ |
| 370 | return UserUserGroup::create([ |
| 371 | 'userId' => $userId, |
| 372 | 'userGroupId' => $userGroupId, |
| 373 | 'dateStart' => $dateStart, |
| 374 | 'dateEnd' => $endDate, |
| 375 | 'masthead' => $masthead, |
| 376 | ]); |
| 377 | } |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 352 | $dateStart = $startDate ?? Core::getCurrentDate(); |
| 353 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 354 | // user_user_group's masthead does not inherit from the user_group's masthead, |
| 355 | // it needs to be specified (when accepting an invitations). |
| 356 | switch ($mastheadStatus) { |
| 357 | case UserUserGroupMastheadStatus::STATUS_ON: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 364 | $masthead = $userGroup->getMasthead() ? 1 : null; |
| 365 | } |
| 366 | // Clear editorial masthead cache if a new user is assigned to a masthead role |
| 367 | if ($userGroup->getMasthead()) { |
| 367 | if ($userGroup->getMasthead()) { |
| 370 | return UserUserGroup::create([ |
| 371 | 'userId' => $userId, |
| 372 | 'userGroupId' => $userGroupId, |
| 373 | 'dateStart' => $dateStart, |
| 374 | 'dateEnd' => $endDate, |
| 375 | 'masthead' => $masthead, |
| 376 | ]); |
| 377 | } |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 352 | $dateStart = $startDate ?? Core::getCurrentDate(); |
| 353 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 354 | // user_user_group's masthead does not inherit from the user_group's masthead, |
| 355 | // it needs to be specified (when accepting an invitations). |
| 356 | switch ($mastheadStatus) { |
| 357 | case UserUserGroupMastheadStatus::STATUS_ON: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 361 | $masthead = 0; |
| 362 | break; |
| 367 | if ($userGroup->getMasthead()) { |
| 368 | self::forgetEditorialMastheadCache($userGroup->getContextId()); |
| 369 | } |
| 370 | return UserUserGroup::create([ |
| 370 | return UserUserGroup::create([ |
| 371 | 'userId' => $userId, |
| 372 | 'userGroupId' => $userGroupId, |
| 373 | 'dateStart' => $dateStart, |
| 374 | 'dateEnd' => $endDate, |
| 375 | 'masthead' => $masthead, |
| 376 | ]); |
| 377 | } |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 352 | $dateStart = $startDate ?? Core::getCurrentDate(); |
| 353 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 354 | // user_user_group's masthead does not inherit from the user_group's masthead, |
| 355 | // it needs to be specified (when accepting an invitations). |
| 356 | switch ($mastheadStatus) { |
| 357 | case UserUserGroupMastheadStatus::STATUS_ON: |
| 360 | case UserUserGroupMastheadStatus::STATUS_OFF: |
| 361 | $masthead = 0; |
| 362 | break; |
| 367 | if ($userGroup->getMasthead()) { |
| 370 | return UserUserGroup::create([ |
| 371 | 'userId' => $userId, |
| 372 | 'userGroupId' => $userGroupId, |
| 373 | 'dateStart' => $dateStart, |
| 374 | 'dateEnd' => $endDate, |
| 375 | 'masthead' => $masthead, |
| 376 | ]); |
| 377 | } |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 352 | $dateStart = $startDate ?? Core::getCurrentDate(); |
| 353 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 354 | // user_user_group's masthead does not inherit from the user_group's masthead, |
| 355 | // it needs to be specified (when accepting an invitations). |
| 356 | switch ($mastheadStatus) { |
| 357 | case UserUserGroupMastheadStatus::STATUS_ON: |
| 358 | $masthead = 1; |
| 359 | break; |
| 367 | if ($userGroup->getMasthead()) { |
| 368 | self::forgetEditorialMastheadCache($userGroup->getContextId()); |
| 369 | } |
| 370 | return UserUserGroup::create([ |
| 370 | return UserUserGroup::create([ |
| 371 | 'userId' => $userId, |
| 372 | 'userGroupId' => $userGroupId, |
| 373 | 'dateStart' => $dateStart, |
| 374 | 'dateEnd' => $endDate, |
| 375 | 'masthead' => $masthead, |
| 376 | ]); |
| 377 | } |
| 346 | public function assignUserToGroup(int $userId, int $userGroupId, ?string $startDate = null, ?string $endDate = null, ?UserUserGroupMastheadStatus $mastheadStatus = null): ?UserUserGroup |
| 347 | { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 348 | if ($endDate && !Carbon::parse($endDate)->isFuture()) { |
| 352 | $dateStart = $startDate ?? Core::getCurrentDate(); |
| 353 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 354 | // user_user_group's masthead does not inherit from the user_group's masthead, |
| 355 | // it needs to be specified (when accepting an invitations). |
| 356 | switch ($mastheadStatus) { |
| 357 | case UserUserGroupMastheadStatus::STATUS_ON: |
| 358 | $masthead = 1; |
| 359 | break; |
| 367 | if ($userGroup->getMasthead()) { |
| 370 | return UserUserGroup::create([ |
| 371 | 'userId' => $userId, |
| 372 | 'userGroupId' => $userGroupId, |
| 373 | 'dateStart' => $dateStart, |
| 374 | 'dateEnd' => $endDate, |
| 375 | 'masthead' => $masthead, |
| 376 | ]); |
| 377 | } |
| 331 | public function contextHasGroup(int $contextId, int $userGroupId): bool |
| 332 | { |
| 333 | return Repo::userGroup() |
| 334 | ->getCollector() |
| 335 | ->filterByContextIds([$contextId]) |
| 336 | ->filterByUserGroupIds([$userGroupId]) |
| 337 | ->getCount() > 0; |
| 338 | } |
| 183 | public function delete(UserGroup $userGroup) |
| 184 | { |
| 185 | Hook::call('UserGroup::delete::before', [$userGroup]); |
| 186 | |
| 187 | $this->dao->delete($userGroup); |
| 188 | |
| 189 | Hook::call('UserGroup::delete', [$userGroup]); |
| 190 | } |
| 382 | public function deleteAssignmentsByUserId(int $userId, ?int $userGroupId = null): bool |
| 383 | { |
| 384 | if (!$userGroupId) { |
| 385 | $contextIds = $this->getUserUserGroupsContextIds($userId); |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 387 | self::forgetEditorialMastheadCache($contextId); |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 387 | self::forgetEditorialMastheadCache($contextId); |
| 388 | self::forgetEditorialHistoryCache($contextId); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 393 | |
| 394 | if ($userGroupId) { |
| 395 | $query->withUserGroupId($userGroupId); |
| 396 | $userGroup = $this->get($userGroupId); |
| 397 | if ($userGroup->getMasthead()) { |
| 398 | self::forgetEditorialMastheadCache($contextId); |
| 399 | self::forgetEditorialHistoryCache($contextId); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | return $query->delete(); |
| 403 | return $query->delete(); |
| 404 | } |
| 382 | public function deleteAssignmentsByUserId(int $userId, ?int $userGroupId = null): bool |
| 383 | { |
| 384 | if (!$userGroupId) { |
| 385 | $contextIds = $this->getUserUserGroupsContextIds($userId); |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 387 | self::forgetEditorialMastheadCache($contextId); |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 387 | self::forgetEditorialMastheadCache($contextId); |
| 388 | self::forgetEditorialHistoryCache($contextId); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 393 | |
| 394 | if ($userGroupId) { |
| 395 | $query->withUserGroupId($userGroupId); |
| 396 | $userGroup = $this->get($userGroupId); |
| 397 | if ($userGroup->getMasthead()) { |
| 403 | return $query->delete(); |
| 404 | } |
| 382 | public function deleteAssignmentsByUserId(int $userId, ?int $userGroupId = null): bool |
| 383 | { |
| 384 | if (!$userGroupId) { |
| 385 | $contextIds = $this->getUserUserGroupsContextIds($userId); |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 387 | self::forgetEditorialMastheadCache($contextId); |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 387 | self::forgetEditorialMastheadCache($contextId); |
| 388 | self::forgetEditorialHistoryCache($contextId); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 393 | |
| 394 | if ($userGroupId) { |
| 403 | return $query->delete(); |
| 404 | } |
| 382 | public function deleteAssignmentsByUserId(int $userId, ?int $userGroupId = null): bool |
| 383 | { |
| 384 | if (!$userGroupId) { |
| 385 | $contextIds = $this->getUserUserGroupsContextIds($userId); |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 387 | self::forgetEditorialMastheadCache($contextId); |
| 388 | self::forgetEditorialHistoryCache($contextId); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 393 | |
| 394 | if ($userGroupId) { |
| 395 | $query->withUserGroupId($userGroupId); |
| 396 | $userGroup = $this->get($userGroupId); |
| 397 | if ($userGroup->getMasthead()) { |
| 398 | self::forgetEditorialMastheadCache($contextId); |
| 399 | self::forgetEditorialHistoryCache($contextId); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | return $query->delete(); |
| 403 | return $query->delete(); |
| 404 | } |
| 382 | public function deleteAssignmentsByUserId(int $userId, ?int $userGroupId = null): bool |
| 383 | { |
| 384 | if (!$userGroupId) { |
| 385 | $contextIds = $this->getUserUserGroupsContextIds($userId); |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 387 | self::forgetEditorialMastheadCache($contextId); |
| 388 | self::forgetEditorialHistoryCache($contextId); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 393 | |
| 394 | if ($userGroupId) { |
| 395 | $query->withUserGroupId($userGroupId); |
| 396 | $userGroup = $this->get($userGroupId); |
| 397 | if ($userGroup->getMasthead()) { |
| 403 | return $query->delete(); |
| 404 | } |
| 382 | public function deleteAssignmentsByUserId(int $userId, ?int $userGroupId = null): bool |
| 383 | { |
| 384 | if (!$userGroupId) { |
| 385 | $contextIds = $this->getUserUserGroupsContextIds($userId); |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 387 | self::forgetEditorialMastheadCache($contextId); |
| 388 | self::forgetEditorialHistoryCache($contextId); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 393 | |
| 394 | if ($userGroupId) { |
| 403 | return $query->delete(); |
| 404 | } |
| 382 | public function deleteAssignmentsByUserId(int $userId, ?int $userGroupId = null): bool |
| 383 | { |
| 384 | if (!$userGroupId) { |
| 385 | $contextIds = $this->getUserUserGroupsContextIds($userId); |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 387 | self::forgetEditorialMastheadCache($contextId); |
| 388 | self::forgetEditorialHistoryCache($contextId); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 393 | |
| 394 | if ($userGroupId) { |
| 395 | $query->withUserGroupId($userGroupId); |
| 396 | $userGroup = $this->get($userGroupId); |
| 397 | if ($userGroup->getMasthead()) { |
| 398 | self::forgetEditorialMastheadCache($contextId); |
| 399 | self::forgetEditorialHistoryCache($contextId); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | return $query->delete(); |
| 403 | return $query->delete(); |
| 404 | } |
| 382 | public function deleteAssignmentsByUserId(int $userId, ?int $userGroupId = null): bool |
| 383 | { |
| 384 | if (!$userGroupId) { |
| 385 | $contextIds = $this->getUserUserGroupsContextIds($userId); |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 387 | self::forgetEditorialMastheadCache($contextId); |
| 388 | self::forgetEditorialHistoryCache($contextId); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 393 | |
| 394 | if ($userGroupId) { |
| 395 | $query->withUserGroupId($userGroupId); |
| 396 | $userGroup = $this->get($userGroupId); |
| 397 | if ($userGroup->getMasthead()) { |
| 403 | return $query->delete(); |
| 404 | } |
| 382 | public function deleteAssignmentsByUserId(int $userId, ?int $userGroupId = null): bool |
| 383 | { |
| 384 | if (!$userGroupId) { |
| 385 | $contextIds = $this->getUserUserGroupsContextIds($userId); |
| 386 | foreach ($contextIds as $contextId) { |
| 386 | foreach ($contextIds as $contextId) { |
| 387 | self::forgetEditorialMastheadCache($contextId); |
| 388 | self::forgetEditorialHistoryCache($contextId); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 393 | |
| 394 | if ($userGroupId) { |
| 403 | return $query->delete(); |
| 404 | } |
| 382 | public function deleteAssignmentsByUserId(int $userId, ?int $userGroupId = null): bool |
| 383 | { |
| 384 | if (!$userGroupId) { |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 393 | |
| 394 | if ($userGroupId) { |
| 395 | $query->withUserGroupId($userGroupId); |
| 396 | $userGroup = $this->get($userGroupId); |
| 397 | if ($userGroup->getMasthead()) { |
| 398 | self::forgetEditorialMastheadCache($contextId); |
| 399 | self::forgetEditorialHistoryCache($contextId); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | return $query->delete(); |
| 403 | return $query->delete(); |
| 404 | } |
| 382 | public function deleteAssignmentsByUserId(int $userId, ?int $userGroupId = null): bool |
| 383 | { |
| 384 | if (!$userGroupId) { |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 393 | |
| 394 | if ($userGroupId) { |
| 395 | $query->withUserGroupId($userGroupId); |
| 396 | $userGroup = $this->get($userGroupId); |
| 397 | if ($userGroup->getMasthead()) { |
| 403 | return $query->delete(); |
| 404 | } |
| 382 | public function deleteAssignmentsByUserId(int $userId, ?int $userGroupId = null): bool |
| 383 | { |
| 384 | if (!$userGroupId) { |
| 392 | $query = UserUserGroup::withUserId($userId); |
| 393 | |
| 394 | if ($userGroupId) { |
| 403 | return $query->delete(); |
| 404 | } |
| 195 | public function deleteByContextId(int $contextId) |
| 196 | { |
| 197 | $userGroupIds = Repo::userGroup()->getCollector() |
| 198 | ->filterByContextIds([$contextId]) |
| 199 | ->getIds(); |
| 200 | |
| 201 | foreach ($userGroupIds as $userGroupId) { |
| 201 | foreach ($userGroupIds as $userGroupId) { |
| 201 | foreach ($userGroupIds as $userGroupId) { |
| 202 | $this->dao->deleteById($userGroupId); |
| 201 | foreach ($userGroupIds as $userGroupId) { |
| 201 | foreach ($userGroupIds as $userGroupId) { |
| 202 | $this->dao->deleteById($userGroupId); |
| 203 | } |
| 204 | } |
| 195 | public function deleteByContextId(int $contextId) |
| 196 | { |
| 197 | $userGroupIds = Repo::userGroup()->getCollector() |
| 198 | ->filterByContextIds([$contextId]) |
| 199 | ->getIds(); |
| 200 | |
| 201 | foreach ($userGroupIds as $userGroupId) { |
| 201 | foreach ($userGroupIds as $userGroupId) { |
| 201 | foreach ($userGroupIds as $userGroupId) { |
| 202 | $this->dao->deleteById($userGroupId); |
| 203 | } |
| 204 | } |
| 195 | public function deleteByContextId(int $contextId) |
| 196 | { |
| 197 | $userGroupIds = Repo::userGroup()->getCollector() |
| 198 | ->filterByContextIds([$contextId]) |
| 199 | ->getIds(); |
| 200 | |
| 201 | foreach ($userGroupIds as $userGroupId) { |
| 201 | foreach ($userGroupIds as $userGroupId) { |
| 202 | $this->dao->deleteById($userGroupId); |
| 203 | } |
| 204 | } |
| 166 | public function edit(UserGroup $userGroup, array $params) |
| 167 | { |
| 168 | $newUserGroup = Repo::userGroup()->newDataObject(array_merge($userGroup->_data, $params)); |
| 169 | |
| 170 | Hook::call('UserGroup::edit', [$newUserGroup, $userGroup, $params]); |
| 171 | |
| 172 | $this->dao->update($newUserGroup); |
| 173 | |
| 174 | // Clear editorial masthead and history cache if the role is on the masthead |
| 175 | if ($userGroup->getMasthead()) { |
| 176 | self::forgetEditorialMastheadCache($userGroup->getContextId()); |
| 177 | self::forgetEditorialHistoryCache($userGroup->getContextId()); |
| 178 | } |
| 179 | |
| 180 | Repo::userGroup()->get($newUserGroup->getId()); |
| 180 | Repo::userGroup()->get($newUserGroup->getId()); |
| 181 | } |
| 166 | public function edit(UserGroup $userGroup, array $params) |
| 167 | { |
| 168 | $newUserGroup = Repo::userGroup()->newDataObject(array_merge($userGroup->_data, $params)); |
| 169 | |
| 170 | Hook::call('UserGroup::edit', [$newUserGroup, $userGroup, $params]); |
| 171 | |
| 172 | $this->dao->update($newUserGroup); |
| 173 | |
| 174 | // Clear editorial masthead and history cache if the role is on the masthead |
| 175 | if ($userGroup->getMasthead()) { |
| 180 | Repo::userGroup()->get($newUserGroup->getId()); |
| 181 | } |
| 406 | public function endAssignments(int $contextId, int $userId, ?int $userGroupId = null): void |
| 407 | { |
| 408 | // Clear editorial masthead and history cache if the user was displayed on the masthead for the given role |
| 409 | if ($this->userOnMasthead($userId, $userGroupId)) { |
| 410 | self::forgetEditorialMastheadCache($contextId); |
| 411 | self::forgetEditorialHistoryCache($contextId); |
| 412 | } |
| 413 | |
| 414 | $dateEnd = Core::getCurrentDate(); |
| 414 | $dateEnd = Core::getCurrentDate(); |
| 415 | $query = UserUserGroup::withContextId($contextId) |
| 416 | ->withUserId($userId) |
| 417 | ->withActive(); |
| 418 | if ($userGroupId) { |
| 419 | $query->withUserGroupId($userGroupId); |
| 420 | } |
| 421 | $query->update(['date_end' => $dateEnd]); |
| 421 | $query->update(['date_end' => $dateEnd]); |
| 422 | } |
| 406 | public function endAssignments(int $contextId, int $userId, ?int $userGroupId = null): void |
| 407 | { |
| 408 | // Clear editorial masthead and history cache if the user was displayed on the masthead for the given role |
| 409 | if ($this->userOnMasthead($userId, $userGroupId)) { |
| 410 | self::forgetEditorialMastheadCache($contextId); |
| 411 | self::forgetEditorialHistoryCache($contextId); |
| 412 | } |
| 413 | |
| 414 | $dateEnd = Core::getCurrentDate(); |
| 414 | $dateEnd = Core::getCurrentDate(); |
| 415 | $query = UserUserGroup::withContextId($contextId) |
| 416 | ->withUserId($userId) |
| 417 | ->withActive(); |
| 418 | if ($userGroupId) { |
| 421 | $query->update(['date_end' => $dateEnd]); |
| 422 | } |
| 406 | public function endAssignments(int $contextId, int $userId, ?int $userGroupId = null): void |
| 407 | { |
| 408 | // Clear editorial masthead and history cache if the user was displayed on the masthead for the given role |
| 409 | if ($this->userOnMasthead($userId, $userGroupId)) { |
| 414 | $dateEnd = Core::getCurrentDate(); |
| 415 | $query = UserUserGroup::withContextId($contextId) |
| 416 | ->withUserId($userId) |
| 417 | ->withActive(); |
| 418 | if ($userGroupId) { |
| 419 | $query->withUserGroupId($userGroupId); |
| 420 | } |
| 421 | $query->update(['date_end' => $dateEnd]); |
| 421 | $query->update(['date_end' => $dateEnd]); |
| 422 | } |
| 406 | public function endAssignments(int $contextId, int $userId, ?int $userGroupId = null): void |
| 407 | { |
| 408 | // Clear editorial masthead and history cache if the user was displayed on the masthead for the given role |
| 409 | if ($this->userOnMasthead($userId, $userGroupId)) { |
| 414 | $dateEnd = Core::getCurrentDate(); |
| 415 | $query = UserUserGroup::withContextId($contextId) |
| 416 | ->withUserId($userId) |
| 417 | ->withActive(); |
| 418 | if ($userGroupId) { |
| 421 | $query->update(['date_end' => $dateEnd]); |
| 422 | } |
| 85 | public function exists(int $id, ?int $contextId = null): bool |
| 86 | { |
| 87 | return $this->dao->exists($id, $contextId); |
| 88 | } |
| 672 | public static function forgetEditorialHistoryCache(int $contextId) |
| 673 | { |
| 674 | Cache::forget('PKP\userGroup\Repository::getMastheadUserIdsByRoleIdsEditorialHistory' . $contextId . self::MAX_EDITORIAL_MASTHEAD_CACHE_LIFETIME); |
| 675 | } |
| 664 | public static function forgetEditorialMastheadCache(int $contextId) |
| 665 | { |
| 666 | Cache::forget('PKP\userGroup\Repository::getMastheadUserIdsByRoleIdsEditorialMasthead' . $contextId . self::MAX_EDITORIAL_MASTHEAD_CACHE_LIFETIME); |
| 667 | } |
| 79 | public function get(int $id, ?int $contextId = null): ?UserGroup |
| 80 | { |
| 81 | return $this->dao->get($id, $contextId); |
| 82 | } |
| 211 | public function getArrayIdByRoleId($roleId, ?int $contextId = null): array |
| 212 | { |
| 213 | $collector = Repo::userGroup()->getCollector() |
| 214 | ->filterByRoleIds([$roleId]); |
| 215 | |
| 216 | if ($contextId) { |
| 217 | $collector->filterByContextIds([$contextId]); |
| 218 | } |
| 219 | |
| 220 | return $collector->getIds()->toArray(); |
| 220 | return $collector->getIds()->toArray(); |
| 221 | } |
| 211 | public function getArrayIdByRoleId($roleId, ?int $contextId = null): array |
| 212 | { |
| 213 | $collector = Repo::userGroup()->getCollector() |
| 214 | ->filterByRoleIds([$roleId]); |
| 215 | |
| 216 | if ($contextId) { |
| 220 | return $collector->getIds()->toArray(); |
| 221 | } |
| 465 | public function getAssignedStagesByUserGroupId(int $contextId, int $userGroupId): Collection |
| 466 | { |
| 467 | return UserGroupStage::withContextId($contextId) |
| 468 | ->withUserGroupId($userGroupId) |
| 469 | ->pluck('stage_id'); |
| 470 | } |
| 230 | public function getByRoleIds(array $roleIds, int $contextId, ?bool $default = null): LazyCollection |
| 231 | { |
| 232 | $collector = Repo::userGroup() |
| 233 | ->getCollector() |
| 234 | ->filterByRoleIds($roleIds) |
| 235 | ->filterByContextIds([$contextId]) |
| 236 | ->filterByIsDefault($default); |
| 237 | |
| 238 | return $collector->getMany(); |
| 239 | } |
| 93 | return app(Collector::class); |
| 94 | } |
| 488 | public function getFirstSubmitAsAuthorUserGroup(int $contextId): ?UserGroup |
| 489 | { |
| 490 | return Repo::userGroup() |
| 491 | ->getCollector() |
| 492 | ->filterByContextIds([$contextId]) |
| 493 | ->filterByRoleIds([Role::ROLE_ID_AUTHOR]) |
| 494 | ->filterByPermitSelfRegistration(true) |
| 495 | ->limit(1) |
| 496 | ->getMany() |
| 497 | ->first(); |
| 498 | } |
| 614 | public function getMastheadUserIdsByRoleIds(array $mastheadRoles, int $contextId, UserUserGroupStatus $userUserGroupStatus = UserUserGroupStatus::STATUS_ACTIVE): array |
| 615 | { |
| 616 | $key = __METHOD__; |
| 617 | switch ($userUserGroupStatus) { |
| 618 | case UserUserGroupStatus::STATUS_ACTIVE: |
| 621 | case UserUserGroupStatus::STATUS_ENDED: |
| 621 | case UserUserGroupStatus::STATUS_ENDED: |
| 625 | $key .= $contextId . self::MAX_EDITORIAL_MASTHEAD_CACHE_LIFETIME; |
| 626 | $expiration = DateInterval::createFromDateString(static::MAX_EDITORIAL_MASTHEAD_CACHE_LIFETIME); |
| 627 | $allUsersIdsGroupedByUserGroupId = Cache::remember($key, $expiration, function () use ($mastheadRoles, $contextId, $userUserGroupStatus) { |
| 628 | $mastheadRolesIds = array_map( |
| 629 | function (UserGroup $item) use ($contextId) { |
| 630 | if ($item->getContextId() == $contextId) { |
| 631 | return $item->getId(); |
| 632 | } |
| 633 | }, |
| 634 | $mastheadRoles |
| 635 | ); |
| 636 | // Query that gets all users that are or were active in the given masthead roles |
| 637 | // and that have accepted to be displayed on the masthead for the roles. |
| 638 | // Sort the results by role ID and user family name. |
| 639 | $usersCollector = Repo::user()->getCollector(); |
| 640 | $usersQuery = $usersCollector |
| 641 | ->filterByContextIds([$contextId]) |
| 642 | ->filterByUserGroupIds($mastheadRolesIds) |
| 643 | ->filterByUserUserGroupStatus($userUserGroupStatus) |
| 644 | ->filterByUserUserGroupMastheadStatus(UserUserGroupMastheadStatus::STATUS_ON) |
| 645 | ->orderBy($usersCollector::ORDERBY_FAMILYNAME, $usersCollector::ORDER_DIR_ASC, [Locale::getLocale(), Application::get()->getRequest()->getSite()->getPrimaryLocale()]) |
| 646 | ->orderByUserGroupIds($mastheadRolesIds) |
| 647 | ->getQueryBuilder() |
| 648 | ->get(); |
| 649 | |
| 650 | // Get unique user IDs grouped by user group ID |
| 651 | $userIdsByUserGroupId = $usersQuery->mapToGroups(function (stdClass $item, int $key) { |
| 652 | return [$item->user_group_id => $item->user_id]; |
| 653 | })->map(function ($item) { |
| 654 | return collect($item)->unique(); |
| 655 | }); |
| 656 | return $userIdsByUserGroupId->toArray(); |
| 657 | }); |
| 658 | return $allUsersIdsGroupedByUserGroupId; |
| 659 | } |
| 614 | public function getMastheadUserIdsByRoleIds(array $mastheadRoles, int $contextId, UserUserGroupStatus $userUserGroupStatus = UserUserGroupStatus::STATUS_ACTIVE): array |
| 615 | { |
| 616 | $key = __METHOD__; |
| 617 | switch ($userUserGroupStatus) { |
| 618 | case UserUserGroupStatus::STATUS_ACTIVE: |
| 621 | case UserUserGroupStatus::STATUS_ENDED: |
| 622 | $key .= 'EditorialHistory'; |
| 623 | break; |
| 625 | $key .= $contextId . self::MAX_EDITORIAL_MASTHEAD_CACHE_LIFETIME; |
| 626 | $expiration = DateInterval::createFromDateString(static::MAX_EDITORIAL_MASTHEAD_CACHE_LIFETIME); |
| 627 | $allUsersIdsGroupedByUserGroupId = Cache::remember($key, $expiration, function () use ($mastheadRoles, $contextId, $userUserGroupStatus) { |
| 628 | $mastheadRolesIds = array_map( |
| 629 | function (UserGroup $item) use ($contextId) { |
| 630 | if ($item->getContextId() == $contextId) { |
| 631 | return $item->getId(); |
| 632 | } |
| 633 | }, |
| 634 | $mastheadRoles |
| 635 | ); |
| 636 | // Query that gets all users that are or were active in the given masthead roles |
| 637 | // and that have accepted to be displayed on the masthead for the roles. |
| 638 | // Sort the results by role ID and user family name. |
| 639 | $usersCollector = Repo::user()->getCollector(); |
| 640 | $usersQuery = $usersCollector |
| 641 | ->filterByContextIds([$contextId]) |
| 642 | ->filterByUserGroupIds($mastheadRolesIds) |
| 643 | ->filterByUserUserGroupStatus($userUserGroupStatus) |
| 644 | ->filterByUserUserGroupMastheadStatus(UserUserGroupMastheadStatus::STATUS_ON) |
| 645 | ->orderBy($usersCollector::ORDERBY_FAMILYNAME, $usersCollector::ORDER_DIR_ASC, [Locale::getLocale(), Application::get()->getRequest()->getSite()->getPrimaryLocale()]) |
| 646 | ->orderByUserGroupIds($mastheadRolesIds) |
| 647 | ->getQueryBuilder() |
| 648 | ->get(); |
| 649 | |
| 650 | // Get unique user IDs grouped by user group ID |
| 651 | $userIdsByUserGroupId = $usersQuery->mapToGroups(function (stdClass $item, int $key) { |
| 652 | return [$item->user_group_id => $item->user_id]; |
| 653 | })->map(function ($item) { |
| 654 | return collect($item)->unique(); |
| 655 | }); |
| 656 | return $userIdsByUserGroupId->toArray(); |
| 657 | }); |
| 658 | return $allUsersIdsGroupedByUserGroupId; |
| 659 | } |
| 614 | public function getMastheadUserIdsByRoleIds(array $mastheadRoles, int $contextId, UserUserGroupStatus $userUserGroupStatus = UserUserGroupStatus::STATUS_ACTIVE): array |
| 615 | { |
| 616 | $key = __METHOD__; |
| 617 | switch ($userUserGroupStatus) { |
| 618 | case UserUserGroupStatus::STATUS_ACTIVE: |
| 619 | $key .= 'EditorialMasthead'; |
| 620 | break; |
| 625 | $key .= $contextId . self::MAX_EDITORIAL_MASTHEAD_CACHE_LIFETIME; |
| 626 | $expiration = DateInterval::createFromDateString(static::MAX_EDITORIAL_MASTHEAD_CACHE_LIFETIME); |
| 627 | $allUsersIdsGroupedByUserGroupId = Cache::remember($key, $expiration, function () use ($mastheadRoles, $contextId, $userUserGroupStatus) { |
| 628 | $mastheadRolesIds = array_map( |
| 629 | function (UserGroup $item) use ($contextId) { |
| 630 | if ($item->getContextId() == $contextId) { |
| 631 | return $item->getId(); |
| 632 | } |
| 633 | }, |
| 634 | $mastheadRoles |
| 635 | ); |
| 636 | // Query that gets all users that are or were active in the given masthead roles |
| 637 | // and that have accepted to be displayed on the masthead for the roles. |
| 638 | // Sort the results by role ID and user family name. |
| 639 | $usersCollector = Repo::user()->getCollector(); |
| 640 | $usersQuery = $usersCollector |
| 641 | ->filterByContextIds([$contextId]) |
| 642 | ->filterByUserGroupIds($mastheadRolesIds) |
| 643 | ->filterByUserUserGroupStatus($userUserGroupStatus) |
| 644 | ->filterByUserUserGroupMastheadStatus(UserUserGroupMastheadStatus::STATUS_ON) |
| 645 | ->orderBy($usersCollector::ORDERBY_FAMILYNAME, $usersCollector::ORDER_DIR_ASC, [Locale::getLocale(), Application::get()->getRequest()->getSite()->getPrimaryLocale()]) |
| 646 | ->orderByUserGroupIds($mastheadRolesIds) |
| 647 | ->getQueryBuilder() |
| 648 | ->get(); |
| 649 | |
| 650 | // Get unique user IDs grouped by user group ID |
| 651 | $userIdsByUserGroupId = $usersQuery->mapToGroups(function (stdClass $item, int $key) { |
| 652 | return [$item->user_group_id => $item->user_id]; |
| 653 | })->map(function ($item) { |
| 654 | return collect($item)->unique(); |
| 655 | }); |
| 656 | return $userIdsByUserGroupId->toArray(); |
| 657 | }); |
| 658 | return $allUsersIdsGroupedByUserGroupId; |
| 659 | } |
| 102 | return app('maps')->withExtensions($this->schemaMap); |
| 103 | } |
| 475 | public function getUserCountByContextId(?int $contextId = null): Collection |
| 476 | { |
| 477 | return $this->dao->getUserCountByContextId($contextId); |
| 478 | } |
| 432 | public function getUserGroupsByStage(int $contextId, $stageId, $roleId = null, $count = null): LazyCollection |
| 433 | { |
| 434 | $userGroups = $this->getCollector() |
| 435 | ->filterByContextIds([$contextId]) |
| 436 | ->filterByStageIds([$stageId]); |
| 437 | |
| 438 | if ($roleId) { |
| 439 | $userGroups->filterByRoleIds([$roleId]); |
| 440 | } |
| 441 | |
| 442 | $userGroups->orderBy(Collector::ORDERBY_ROLE_ID); |
| 442 | $userGroups->orderBy(Collector::ORDERBY_ROLE_ID); |
| 443 | |
| 444 | return $userGroups->getMany(); |
| 445 | } |
| 432 | public function getUserGroupsByStage(int $contextId, $stageId, $roleId = null, $count = null): LazyCollection |
| 433 | { |
| 434 | $userGroups = $this->getCollector() |
| 435 | ->filterByContextIds([$contextId]) |
| 436 | ->filterByStageIds([$stageId]); |
| 437 | |
| 438 | if ($roleId) { |
| 442 | $userGroups->orderBy(Collector::ORDERBY_ROLE_ID); |
| 443 | |
| 444 | return $userGroups->getMany(); |
| 445 | } |
| 312 | public function getUserUserGroupMastheadStatus(int $userId, int $userGroupId): UserUserGroupMastheadStatus |
| 313 | { |
| 314 | $masthead = UserUserGroup::withUserId($userId) |
| 315 | ->withUserGroupId($userGroupId) |
| 316 | ->withActive() |
| 317 | ->pluck('masthead'); |
| 318 | switch ($masthead[0]) { |
| 319 | case 1: |
| 321 | case 0: |
| 318 | switch ($masthead[0]) { |
| 318 | switch ($masthead[0]) { |
| 324 | return UserUserGroupMastheadStatus::STATUS_NULL; |
| 325 | } |
| 326 | } |
| 312 | public function getUserUserGroupMastheadStatus(int $userId, int $userGroupId): UserUserGroupMastheadStatus |
| 313 | { |
| 314 | $masthead = UserUserGroup::withUserId($userId) |
| 315 | ->withUserGroupId($userGroupId) |
| 316 | ->withActive() |
| 317 | ->pluck('masthead'); |
| 318 | switch ($masthead[0]) { |
| 319 | case 1: |
| 321 | case 0: |
| 318 | switch ($masthead[0]) { |
| 324 | return UserUserGroupMastheadStatus::STATUS_NULL; |
| 312 | public function getUserUserGroupMastheadStatus(int $userId, int $userGroupId): UserUserGroupMastheadStatus |
| 313 | { |
| 314 | $masthead = UserUserGroup::withUserId($userId) |
| 315 | ->withUserGroupId($userGroupId) |
| 316 | ->withActive() |
| 317 | ->pluck('masthead'); |
| 318 | switch ($masthead[0]) { |
| 319 | case 1: |
| 321 | case 0: |
| 322 | return UserUserGroupMastheadStatus::STATUS_OFF; |
| 312 | public function getUserUserGroupMastheadStatus(int $userId, int $userGroupId): UserUserGroupMastheadStatus |
| 313 | { |
| 314 | $masthead = UserUserGroup::withUserId($userId) |
| 315 | ->withUserGroupId($userGroupId) |
| 316 | ->withActive() |
| 317 | ->pluck('masthead'); |
| 318 | switch ($masthead[0]) { |
| 319 | case 1: |
| 320 | return UserUserGroupMastheadStatus::STATUS_ON; |
| 265 | public function getUserUserGroupsContextIds(int $userId): Collection |
| 266 | { |
| 267 | return Repo::userGroup() |
| 268 | ->getCollector() |
| 269 | ->filterByUserIds([$userId]) |
| 270 | ->filterByUserUserGroupStatus(UserUserGroupStatus::STATUS_ALL) |
| 271 | ->filterByMasthead(true) |
| 272 | ->getQueryBuilder() |
| 273 | ->pluck('context_id') |
| 274 | ->unique(); |
| 275 | } |
| 588 | public function installLocale($locale, ?int $contextId = null) |
| 589 | { |
| 590 | $userGroupsCollector = $this->getCollector(); |
| 591 | |
| 592 | if (isset($contextId)) { |
| 593 | $userGroupsCollector->filterByContextIds([$contextId]); |
| 594 | } |
| 595 | |
| 596 | $userGroups = $userGroupsCollector->getMany(); |
| 596 | $userGroups = $userGroupsCollector->getMany(); |
| 597 | |
| 598 | foreach ($userGroups as $userGroup) { |
| 598 | foreach ($userGroups as $userGroup) { |
| 598 | foreach ($userGroups as $userGroup) { |
| 599 | $nameKey = $userGroup->getData('nameLocaleKey'); |
| 598 | foreach ($userGroups as $userGroup) { |
| 598 | foreach ($userGroups as $userGroup) { |
| 599 | $nameKey = $userGroup->getData('nameLocaleKey'); |
| 600 | $userGroup->setData('name', __($nameKey, [], $locale), $locale); |
| 601 | $abbrevKey = $userGroup->getData('abbrevLocaleKey'); |
| 602 | $userGroup->setData('abbrev', __($abbrevKey, [], $locale), $locale); |
| 603 | |
| 604 | $this->edit($userGroup, []); |
| 605 | } |
| 606 | } |
| 588 | public function installLocale($locale, ?int $contextId = null) |
| 589 | { |
| 590 | $userGroupsCollector = $this->getCollector(); |
| 591 | |
| 592 | if (isset($contextId)) { |
| 593 | $userGroupsCollector->filterByContextIds([$contextId]); |
| 594 | } |
| 595 | |
| 596 | $userGroups = $userGroupsCollector->getMany(); |
| 596 | $userGroups = $userGroupsCollector->getMany(); |
| 597 | |
| 598 | foreach ($userGroups as $userGroup) { |
| 598 | foreach ($userGroups as $userGroup) { |
| 598 | foreach ($userGroups as $userGroup) { |
| 599 | $nameKey = $userGroup->getData('nameLocaleKey'); |
| 600 | $userGroup->setData('name', __($nameKey, [], $locale), $locale); |
| 601 | $abbrevKey = $userGroup->getData('abbrevLocaleKey'); |
| 602 | $userGroup->setData('abbrev', __($abbrevKey, [], $locale), $locale); |
| 603 | |
| 604 | $this->edit($userGroup, []); |
| 605 | } |
| 606 | } |
| 588 | public function installLocale($locale, ?int $contextId = null) |
| 589 | { |
| 590 | $userGroupsCollector = $this->getCollector(); |
| 591 | |
| 592 | if (isset($contextId)) { |
| 593 | $userGroupsCollector->filterByContextIds([$contextId]); |
| 594 | } |
| 595 | |
| 596 | $userGroups = $userGroupsCollector->getMany(); |
| 596 | $userGroups = $userGroupsCollector->getMany(); |
| 597 | |
| 598 | foreach ($userGroups as $userGroup) { |
| 598 | foreach ($userGroups as $userGroup) { |
| 599 | $nameKey = $userGroup->getData('nameLocaleKey'); |
| 600 | $userGroup->setData('name', __($nameKey, [], $locale), $locale); |
| 601 | $abbrevKey = $userGroup->getData('abbrevLocaleKey'); |
| 602 | $userGroup->setData('abbrev', __($abbrevKey, [], $locale), $locale); |
| 603 | |
| 604 | $this->edit($userGroup, []); |
| 605 | } |
| 606 | } |
| 588 | public function installLocale($locale, ?int $contextId = null) |
| 589 | { |
| 590 | $userGroupsCollector = $this->getCollector(); |
| 591 | |
| 592 | if (isset($contextId)) { |
| 596 | $userGroups = $userGroupsCollector->getMany(); |
| 597 | |
| 598 | foreach ($userGroups as $userGroup) { |
| 598 | foreach ($userGroups as $userGroup) { |
| 598 | foreach ($userGroups as $userGroup) { |
| 599 | $nameKey = $userGroup->getData('nameLocaleKey'); |
| 598 | foreach ($userGroups as $userGroup) { |
| 598 | foreach ($userGroups as $userGroup) { |
| 599 | $nameKey = $userGroup->getData('nameLocaleKey'); |
| 600 | $userGroup->setData('name', __($nameKey, [], $locale), $locale); |
| 601 | $abbrevKey = $userGroup->getData('abbrevLocaleKey'); |
| 602 | $userGroup->setData('abbrev', __($abbrevKey, [], $locale), $locale); |
| 603 | |
| 604 | $this->edit($userGroup, []); |
| 605 | } |
| 606 | } |
| 588 | public function installLocale($locale, ?int $contextId = null) |
| 589 | { |
| 590 | $userGroupsCollector = $this->getCollector(); |
| 591 | |
| 592 | if (isset($contextId)) { |
| 596 | $userGroups = $userGroupsCollector->getMany(); |
| 597 | |
| 598 | foreach ($userGroups as $userGroup) { |
| 598 | foreach ($userGroups as $userGroup) { |
| 598 | foreach ($userGroups as $userGroup) { |
| 599 | $nameKey = $userGroup->getData('nameLocaleKey'); |
| 600 | $userGroup->setData('name', __($nameKey, [], $locale), $locale); |
| 601 | $abbrevKey = $userGroup->getData('abbrevLocaleKey'); |
| 602 | $userGroup->setData('abbrev', __($abbrevKey, [], $locale), $locale); |
| 603 | |
| 604 | $this->edit($userGroup, []); |
| 605 | } |
| 606 | } |
| 588 | public function installLocale($locale, ?int $contextId = null) |
| 589 | { |
| 590 | $userGroupsCollector = $this->getCollector(); |
| 591 | |
| 592 | if (isset($contextId)) { |
| 596 | $userGroups = $userGroupsCollector->getMany(); |
| 597 | |
| 598 | foreach ($userGroups as $userGroup) { |
| 598 | foreach ($userGroups as $userGroup) { |
| 599 | $nameKey = $userGroup->getData('nameLocaleKey'); |
| 600 | $userGroup->setData('name', __($nameKey, [], $locale), $locale); |
| 601 | $abbrevKey = $userGroup->getData('abbrevLocaleKey'); |
| 602 | $userGroup->setData('abbrev', __($abbrevKey, [], $locale), $locale); |
| 603 | |
| 604 | $this->edit($userGroup, []); |
| 605 | } |
| 606 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 518 | return false; |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 508 | public function installSettings(?int $contextId, $filename) |
| 509 | { |
| 510 | $xmlParser = new PKPXMLParser(); |
| 511 | $tree = $xmlParser->parse($filename); |
| 512 | |
| 513 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 514 | $site = $siteDao->getSite(); |
| 515 | $installedLocales = $site->getInstalledLocales(); |
| 516 | |
| 517 | if (!$tree) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 521 | foreach ($tree->getChildren() as $setting) { |
| 522 | $roleId = hexdec($setting->getAttribute('roleId')); |
| 523 | $nameKey = $setting->getAttribute('name'); |
| 524 | $abbrevKey = $setting->getAttribute('abbrev'); |
| 525 | $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); |
| 526 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 527 | $masthead = $setting->getAttribute('masthead'); |
| 528 | |
| 529 | // If has manager role then permitMetadataEdit can't be overridden |
| 530 | if (in_array($roleId, [Role::ROLE_ID_MANAGER])) { |
| 531 | $permitMetadataEdit = $setting->getAttribute('permitMetadataEdit'); |
| 532 | } |
| 533 | |
| 534 | $defaultStages = explode(',', (string) $setting->getAttribute('stages')); |
| 535 | |
| 536 | // create a role associated with this user group |
| 537 | $userGroup = $this->newDataObject(); |
| 538 | $userGroup->setRoleId($roleId); |
| 539 | $userGroup->setContextId($contextId); |
| 540 | $userGroup->setPermitSelfRegistration($permitSelfRegistration ?? false); |
| 541 | $userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false); |
| 542 | $userGroup->setDefault(true); |
| 543 | $userGroup->setShowTitle(true); |
| 544 | $userGroup->setMasthead($masthead ?? false); |
| 545 | |
| 546 | // insert the group into the DB |
| 547 | $userGroupId = $this->add($userGroup); |
| 548 | |
| 549 | // Install default groups for each stage |
| 550 | if (is_array($defaultStages)) { // test for groups with no stage assignments |
| 551 | foreach ($defaultStages as $stageId) { |
| 552 | if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { |
| 553 | UserGroupStage::create([ |
| 554 | 'contextId' => $contextId, |
| 555 | 'userGroupId' => $userGroupId, |
| 556 | 'stageId' => $stageId |
| 557 | ]); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // add the i18n keys to the settings table so that they |
| 563 | // can be used when a new locale is added/reloaded |
| 564 | $newUserGroup = $this->get($userGroupId); |
| 565 | $this->edit($newUserGroup, [ |
| 566 | 'nameLocaleKey' => $nameKey, |
| 567 | 'abbrevLocaleKey' => $abbrevKey |
| 568 | ]); |
| 569 | |
| 570 | // install the settings in the current locale for this context |
| 571 | foreach ($installedLocales as $locale) { |
| 572 | $this->installLocale($locale, $contextId); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | self::forgetEditorialMastheadCache($contextId); |
| 577 | self::forgetEditorialHistoryCache($contextId); |
| 578 | |
| 579 | return true; |
| 580 | } |
| 69 | public function newDataObject(array $params = []): UserGroup |
| 70 | { |
| 71 | $object = $this->dao->newDataObject(); |
| 72 | if (!empty($params)) { |
| 73 | $object->setAllData($params); |
| 74 | } |
| 75 | return $object; |
| 75 | return $object; |
| 76 | } |
| 69 | public function newDataObject(array $params = []): UserGroup |
| 70 | { |
| 71 | $object = $this->dao->newDataObject(); |
| 72 | if (!empty($params)) { |
| 75 | return $object; |
| 76 | } |
| 450 | public function removeGroupFromStage(int $contextId, int $userGroupId, int $stageId): bool |
| 451 | { |
| 452 | return UserGroupStage::withContextId($contextId) |
| 453 | ->withUserGroupId($userGroupId) |
| 454 | ->withStageId($stageId) |
| 455 | ->delete(); |
| 456 | } |
| 280 | public function userInGroup(int $userId, int $userGroupId): bool |
| 281 | { |
| 282 | return UserUserGroup::withUserId($userId) |
| 283 | ->withUserGroupId($userGroupId) |
| 284 | ->withActive() |
| 285 | ->get() |
| 286 | ->isNotEmpty(); |
| 287 | } |
| 292 | public function userOnMasthead(int $userId, ?int $userGroupId): bool |
| 293 | { |
| 294 | if ($userGroupId) { |
| 295 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 296 | if (!$userGroup->getMasthead()) { |
| 297 | return false; |
| 292 | public function userOnMasthead(int $userId, ?int $userGroupId): bool |
| 293 | { |
| 294 | if ($userGroupId) { |
| 295 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 296 | if (!$userGroup->getMasthead()) { |
| 300 | $query = UserUserGroup::withUserId($userId) |
| 301 | ->withActive() |
| 302 | ->withMasthead(); |
| 303 | if ($userGroupId) { |
| 304 | $query->withUserGroupId($userGroupId); |
| 305 | } |
| 306 | return $query->get()->isNotEmpty(); |
| 306 | return $query->get()->isNotEmpty(); |
| 307 | } |
| 292 | public function userOnMasthead(int $userId, ?int $userGroupId): bool |
| 293 | { |
| 294 | if ($userGroupId) { |
| 295 | $userGroup = Repo::userGroup()->get($userGroupId); |
| 296 | if (!$userGroup->getMasthead()) { |
| 300 | $query = UserUserGroup::withUserId($userId) |
| 301 | ->withActive() |
| 302 | ->withMasthead(); |
| 303 | if ($userGroupId) { |
| 306 | return $query->get()->isNotEmpty(); |
| 307 | } |
| 292 | public function userOnMasthead(int $userId, ?int $userGroupId): bool |
| 293 | { |
| 294 | if ($userGroupId) { |
| 300 | $query = UserUserGroup::withUserId($userId) |
| 301 | ->withActive() |
| 302 | ->withMasthead(); |
| 303 | if ($userGroupId) { |
| 304 | $query->withUserGroupId($userGroupId); |
| 305 | } |
| 306 | return $query->get()->isNotEmpty(); |
| 306 | return $query->get()->isNotEmpty(); |
| 307 | } |
| 292 | public function userOnMasthead(int $userId, ?int $userGroupId): bool |
| 293 | { |
| 294 | if ($userGroupId) { |
| 300 | $query = UserUserGroup::withUserId($userId) |
| 301 | ->withActive() |
| 302 | ->withMasthead(); |
| 303 | if ($userGroupId) { |
| 306 | return $query->get()->isNotEmpty(); |
| 307 | } |
| 246 | public function userUserGroups(int $userId, ?int $contextId = null, ?UserUserGroupStatus $userUserGroupStatus = UserUserGroupStatus::STATUS_ACTIVE): LazyCollection |
| 247 | { |
| 248 | $collector = Repo::userGroup() |
| 249 | ->getCollector() |
| 250 | ->filterByUserIds([$userId]) |
| 251 | ->filterByUserUserGroupStatus($userUserGroupStatus); |
| 252 | |
| 253 | if ($contextId) { |
| 254 | $collector->filterByContextIds([$contextId]); |
| 255 | } |
| 256 | |
| 257 | return $collector->getMany(); |
| 257 | return $collector->getMany(); |
| 258 | } |
| 246 | public function userUserGroups(int $userId, ?int $contextId = null, ?UserUserGroupStatus $userUserGroupStatus = UserUserGroupStatus::STATUS_ACTIVE): LazyCollection |
| 247 | { |
| 248 | $collector = Repo::userGroup() |
| 249 | ->getCollector() |
| 250 | ->filterByUserIds([$userId]) |
| 251 | ->filterByUserUserGroupStatus($userUserGroupStatus); |
| 252 | |
| 253 | if ($contextId) { |
| 257 | return $collector->getMany(); |
| 258 | } |
| 119 | public function validate($userGroup, $props, $allowedLocales, $primaryLocale) |
| 120 | { |
| 121 | $schemaService = app()->get('schema'); |
| 122 | |
| 123 | $validator = ValidatorFactory::make( |
| 124 | $props, |
| 125 | $schemaService->getValidationRules(PKPSchemaService::SCHEMA_USER_GROUP, $allowedLocales) |
| 126 | ); |
| 127 | |
| 128 | // Check required fields |
| 129 | ValidatorFactory::required( |
| 130 | $validator, |
| 131 | $userGroup, |
| 132 | $schemaService->getRequiredProps(PKPSchemaService::SCHEMA_USER_GROUP), |
| 133 | $schemaService->getMultilingualProps(PKPSchemaService::SCHEMA_USER_GROUP), |
| 134 | $allowedLocales, |
| 135 | $primaryLocale |
| 136 | ); |
| 137 | |
| 138 | // Check for input from disallowed locales |
| 139 | ValidatorFactory::allowedLocales($validator, $schemaService->getMultilingualProps(PKPSchemaService::SCHEMA_USER_GROUP), $allowedLocales); |
| 140 | |
| 141 | $errors = []; |
| 142 | if ($validator->fails()) { |
| 143 | $errors = $schemaService->formatValidationErrors($validator->errors()); |
| 144 | } |
| 145 | |
| 146 | Hook::call('UserGroup::validate', [$errors, $userGroup, $props, $allowedLocales, $primaryLocale]); |
| 146 | Hook::call('UserGroup::validate', [$errors, $userGroup, $props, $allowedLocales, $primaryLocale]); |
| 147 | |
| 148 | return $errors; |
| 149 | } |
| 119 | public function validate($userGroup, $props, $allowedLocales, $primaryLocale) |
| 120 | { |
| 121 | $schemaService = app()->get('schema'); |
| 122 | |
| 123 | $validator = ValidatorFactory::make( |
| 124 | $props, |
| 125 | $schemaService->getValidationRules(PKPSchemaService::SCHEMA_USER_GROUP, $allowedLocales) |
| 126 | ); |
| 127 | |
| 128 | // Check required fields |
| 129 | ValidatorFactory::required( |
| 130 | $validator, |
| 131 | $userGroup, |
| 132 | $schemaService->getRequiredProps(PKPSchemaService::SCHEMA_USER_GROUP), |
| 133 | $schemaService->getMultilingualProps(PKPSchemaService::SCHEMA_USER_GROUP), |
| 134 | $allowedLocales, |
| 135 | $primaryLocale |
| 136 | ); |
| 137 | |
| 138 | // Check for input from disallowed locales |
| 139 | ValidatorFactory::allowedLocales($validator, $schemaService->getMultilingualProps(PKPSchemaService::SCHEMA_USER_GROUP), $allowedLocales); |
| 140 | |
| 141 | $errors = []; |
| 142 | if ($validator->fails()) { |
| 146 | Hook::call('UserGroup::validate', [$errors, $userGroup, $props, $allowedLocales, $primaryLocale]); |
| 147 | |
| 148 | return $errors; |
| 149 | } |